<template>
	<view class="">
	<scroll-view scroll-y="true" class="container" @refresherrefresh="onRefresh" :refresher-enabled="true" :refresher-triggered="triggered" @scrolltolower="lowera()">
		<view class="content" :style="'padding-top:'+barHeight+'px'">
			<view class="search-box">
				<text>要帮忙，找半柿</text>
			</view>
			<view style="height: 24rpx;width: 1rpx;"></view>
			<!-- 搜索 -->
			<view class="search-box">
				<text>半柿</text>
				<view class="search-ipt">
					<image src="../../static/search-img.png" mode=""></image>
					<input v-model="search" @input="resizeInput" type="text" placeholder="请输入关键词">
				</view>
			</view>
			
			<!-- 横排标签 -->
			<scroll-view show-scrollbar="false" scroll-x="true" scroll-y="false" class="scroll-box aa">
				<view class="label" v-for="i in menu" @click="clickkey(i)">
					<image :src="oss(i.image)" mode=""></image>
					<view class="">{{i.name}}</view>
				</view>
			</scroll-view>
			
			<view class="shopping flex f-x-b">
				<image v-for="i in prefecture" @click="goto(i.url)" :src="oss(i.image)" mode=""></image>
			</view>
			<view class="tags-box">
				<view @click="checka(index)" :class="{'checked-tag':current == index}" class="tag" v-for="(item,index) in tag">{{item}}</view>
			</view>
			
			<view class="list-box">
				<u-empty mode="list" v-if="houseList.length == 0" icon="http://cdn.uviewui.com/uview/empty/list.png">
				</u-empty>
				<view v-else class="each-box" @click="godetail(item.id,item.type)" v-for="(item,index) in houseList">
					<view class="img">
						<image :src="oss(item.face_image)" mode="aspectFill"></image>
						<image class="video_img" v-if="item.video" style="width: 38rpx;height: 38rpx;" src="../../static/video.png" mode=""></image>
					</view>
					<view class="text-box">
						<view class="title"> <text class="top" v-if="item.switch">置顶</text> {{item.title}} </view>
						<view class="tags">
							<text class="each-tag" v-for="i in item.facilities">{{i}}</text>
						</view>
						<view v-if="item.type == 'transference'" class="parameter">{{item.area}}㎡ / {{item.village}}</view>
						<view v-if="item.type != 'transference'" class="parameter">{{item.num_room}}室{{item.num_parlor}}厅{{item.num_toilet}}卫 / {{item.area}}㎡ / {{item.village}}</view>
						<view class="price" v-if="item.type=='house'"> <text class="text">{{item.total_price==0?'面议':item.total_price}}</text> <text v-if="item.total_price != 0">万</text> </view>
						<view class="price" v-if="item.type=='rent'">
							 <text class="text">{{item.unit_price==0?'面议':item.unit_price}}</text> <text v-if="item.unit_price != 0">元/月</text> 
						</view>
						<view class="price" v-if="item.type=='transference'">
							<text class="text">{{item.price==0?'面议':item.price}}</text> <text v-if="item.price != 0">元/月</text> 
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" icon-type="flower" bg-color="transperant" margin-top="30" margin-bottom="30" />
		</view>
	</scroll-view>
	<view class="issue" @click="toissue">
		发布信息
	</view>
	
	<u-popup :show="showWhetherGz" @close="showWhetherGz = false" mode="center" :round="20">
		<view class="serveBox">
			<image :src="gz" mode="" class="icon" :show-menu-by-longpress='true'></image>
			<text class="word">长按图片，关注公众号，第一时间了解最新同城信息</text>
			<view style="padding-top: 32rpx;" @click="closeGz">关闭</view>
			<!-- <text class="word">关注公众号</text> -->
		</view>
	</u-popup>
	</view>
</template>

<script>
	import tabbar from "../../components/tabbar/tabbar.vue"
	import amap from '../../common/amap-wx.130.js';
	export default {
		components: {
			tabbar
		},
		data() {
			return {
				barHeight: 0,
				menu:[],
				tag:['默认','二手房','租房','商业地产'],
				current: 0,
				triggered: false,
				_freshing: false,
				refreshText: '',
				page:1,
				houseList:[],//二手房们
				status: 'loadmore',
				flag: false,
				prefecture:'',
				search:'',
				tabBarIndex: 1,
				showWhetherGz:false,
				gz:'https://www.stck.cc/gz.jpg'
			}
		},
		onReachBottom() {
			console.log('````````````')
			//避免多次触发
			if (this.status == 'loading' || this.status == 'nomore') {
				return;
			}
			this.status = 'loading';
			if(this.current == 0){
				this.getdefault()//默认
			}
			if(this.current == 1){
				this.gethouseList()//二手房
			}
			if(this.current == 2){
				this.getrentgetList()//出租房
			}
			if(this.current == 3){
				this.gettransferenceList()//商业地产
			}
		},
		onLoad() {
			this.barHeight = uni.getSystemInfoSync().statusBarHeight
			this.getMenu()
			// this.getdefault()//默认
			this.zone()
			
			this.houseList = []
			this.page = 1
			if(this.current == 0){
				this.getdefault()//默认
			}
			if(this.current == 1){
				this.gethouseList()//二手房
			}
			if(this.current == 2){
				this.getrentgetList()//出租房
			}
			if(this.current == 3){
				this.gettransferenceList()//商业地产
			}
			
			this.getconfig()
			if(uni.getStorageSync('token')){
				this.whetherGz()
			}
		},
		onShow() {
			
		},
		onShareTimeline(){
		    return{
		      title:'要帮忙，找半柿，二手买卖、房屋出租、门面出租、求职招聘、二手房、师傅上门、便民服务各种生活大小事，随时随地帮你解决',  //分享的标题
		      query:'pages/index/index',     //点击分享链接之后进入的页面路径
		      imageUrl:'', // 设置分享卡片图片
		    }
		},
		methods: {
			closeGz(){
				this.showWhetherGz = false
				uni.setStorageSync('gzfollow',1)
			},
			whetherGz() {
				uni.$u.http.post('/gzfollow').then(res => {
					if (res.code == 1) {
						if(res.data == 0){
							if(!uni.getStorageSync('gzfollow')){
								this.showWhetherGz = true
							}
							
						} else {
							this.showWhetherGz = false
						}
					}
				}).catch((res) => {
			
				})
			},
			getconfig() {
				uni.$u.http.post('/getconfig', {
					type:18
				}).then(res => {
					if (res.code == 1) {
						uni.setStorageSync('config',res.data.config)
					}
				}).catch((res) => {
			
				})
			},
			resizeInput(e){
				console.log(e.detail.value)
				this.page = 1
				this.houseList = []
				this.getdefault()//默认
			},
			zone(){
				uni.$u.http.post('/index/zone').then(res => {
					if (res.code == 1) {
						this.prefecture = res.data
					}
				}).catch((res) => {
				
				})
			},
			getMenu(){
				uni.$u.http.post('/index/menu').then(res => {
					if (res.code == 1) {
						this.menu = res.data
					}
				}).catch((res) => {
				
				})
			},
			toissue(){
				if(!uni.getStorageSync('token')){
					uni.$u.route({
						url: 'pagesA/auth/login'
					})
					return
				}
				if(this.current == 0){
					uni.navigateTo({
						url:'/pages/newissue/selectIssue'
					})
				}
				if(this.current == 1){
					uni.navigateTo({
						url:'/pages/newissue/house'
					})
				}
				if(this.current == 2){
					uni.navigateTo({
						url:'/pages/newissue/renting'
					})
				}
				if(this.current == 3){
					uni.navigateTo({
						url:'/pages/newissue/realty'
					})
				}
			},
			//商业地产
			gettransferenceList(){
				this.flag = false
				this.status = 'loading';
				uni.$u.http.post('/transference/getList',{
					page:this.page
				}).then(res => {
					this.triggered = false;
					this._freshing = false;
					if (res.code == 1) {
						this.houseList = this.houseList.concat(res.data)
						if (res.data.length == 0) {
							this.status = 'nomore';
						} else {
							this.page++
							this.status = 'loadmore';
						}
						this.flag = true
						uni.stopPullDownRefresh();
					}
				}).catch((res) => {
				
				})
			},
			//出租房
			getrentgetList(){
				this.flag = false
				this.status = 'loading';
				uni.$u.http.post('/rent/getList',{
					page:this.page
				}).then(res => {
					this.triggered = false;
					this._freshing = false;
					if (res.code == 1) {
						this.houseList = this.houseList.concat(res.data)
						if (res.data.length == 0) {
							this.status = 'nomore';
						} else {
							this.page++
							this.status = 'loadmore';
						}
						this.flag = true
						uni.stopPullDownRefresh();
					}
				}).catch((res) => {
				
				})
			},
			//二手房
			gethouseList(){
				this.flag = false
				this.status = 'loading';
				uni.$u.http.post('/house/getList',{
					page:this.page
				}).then(res => {
					this.triggered = false;
					this._freshing = false;
					if (res.code == 1) {
						this.houseList = this.houseList.concat(res.data)
						if (res.data.length == 0) {
							this.status = 'nomore';
						} else {
							this.page++
							this.status = 'loadmore';
						}
						this.flag = true
						uni.stopPullDownRefresh();
					}
				}).catch((res) => {
				
				})
			},
			//默认
			getdefault(){
				this.flag = false
				this.status = 'loading';
				uni.$u.http.post('/index/indexList',{
					page:this.page,
					search:this.search
				}).then(res => {
					this.triggered = false;
					this._freshing = false;
					if (res.code == 1) {
						this.houseList = this.houseList.concat(res.data)
						if (res.data.length == 0) {
							this.status = 'nomore';
						} else {
							this.page++
							this.status = 'loadmore';
						}
						this.flag = true
						uni.stopPullDownRefresh();
					}
				}).catch((res) => {
				
				})
			},
			onRefresh() {
				if (this._freshing) return;
				this.refreshText = "刷新中...";
				this._freshing = true;
				if (!this.triggered) //界面下拉触发，triggered可能不是true，要设为true  
					this.triggered = true;
				this.reload()
			},
			//点击切换
			checka(index) {
				this.current = index
				this.page = 1
				this.houseList = []
				if(index == 0){
					this.getdefault()//默认
				}
				if(index == 1){
					this.gethouseList()//二手房
				}
				if(index == 2){
					this.getrentgetList()//出租房
				}
				if(index == 3){
					this.gettransferenceList()//商业地产
				}
			},
			//二手车  分类列表
			clickkey(item) {
				console.log(item)
				if(item.type == '三方小程序'){
					uni.navigateToMiniProgram({
					  appId:item.appid,
					  path: '',
					  // extraData: {
					  //   'data1': 'test'
					  // },
					  success(res) {
					    // 打开成功
					  }
					})
					return
				}
				if(item.url == '/pages/serve/serve' || item.url == '/pages/index/indexa' || item.url == '/pages/release/release'){
					uni.switchTab({
						url:item.url
					})
					console.log('1111111111111111111111111')
				} else {
					uni.$u.route({
						url:item.url
					})
				}
			},
			
			reload() {
				console.log('111111111111')
				this.houseList = []
				this.page = 1
				if(this.current == 0){
					this.getdefault()//默认
				}
				if(this.current == 1){
					this.gethouseList()//二手房
				}
				if(this.current == 2){
					this.getrentgetList()//出租房
				}
				if(this.current == 3){
					this.gettransferenceList()//商业地产
				}
			},
			lowera() {
				
			},
			// 跳转商品详情
			godetail(id,type) {
				if(type == 'transference'){
					
				}
				uni.$u.route({
					url: '/pagesA/index/index_detail',
					params: {
						id,
						sort:type == 'house'?1:type=='rent'?2:3
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		position: relative;
		height: 100vh;
		overflow: hidden;
		background-size: 750rpx 500rpx;
		background-repeat: no-repeat;
		background-color: #F6F6F6;
		// display: flex;
		// flex-direction: column;

		.upload {
			width: 113rpx;
			height: 113rpx;
			position: fixed;
			right: 30rpx;
			bottom: 200rpx;
		}

		.container_bg {
			width: 750rpx;
			height: 505rpx;
		}

		.content {
			// position: absolute;
			// top: 0rpx;
			// margin-top: -415rpx;
			
			.search-box {
				display: flex;
				padding: 0 32rpx;
				text {
					font-size: 42rpx;
					font-weight: 800;
				}
				.search-ipt {
					width: 568rpx;
					height: 68rpx;
					background: #FFFFFF;
					border-radius: 39rpx;
					opacity: 1;
					margin-left: 32rpx;
					display: flex;
					align-items: center;
					image {
						width: 28rpx;
						height: 28rpx;
						margin-right: 16rpx;
						margin-left: 32rpx;
					}
				}
			}
			
			
			.tags-box {
				// padding: 0 43rpx;
				display: flex;
				justify-content: space-around;
				margin-top: 48rpx;
				.tag {
					font-size: 26rpx;
					font-weight: 500;
					color: #333333;
				}
				.checked-tag {
					font-size: 28rpx;
					font-weight: bold;
					color: #222;
				}
			}
			// 横排标签
			.scroll-box {
				/* #ifdef MP-TOUTIAO */
				height: 60px;
				/* #endif */
				// overflow: hidden;
				// white-space: nowrap;
				padding: 10rpx 36rpx;

				.label {
					// padding: 0 36rpx;
					margin-top: 45rpx;
					margin-right: 55rpx;
					display: inline-flex;
					flex-direction: column;
					align-items: center;
					border-radius: 40rpx;
					image {
						width: 94rpx;
						height: 94rpx;
						margin-bottom: 13rpx;
					}
					font-size: 24rpx;
					font-weight: 500;
					color: #333333;
					text-align: center;
				}

				.shop_nav {
					margin-right: 60rpx;
					display: flex;
					display: inline-flex;
					flex-direction: column;
					align-items: center;


					.shop_image {
						margin-bottom: 10rpx;
						width: 64rpx;
						height: 70rpx;
					}

					.shop_name {
						font-size: 28rpx;
						color: #333333;
						line-height: 40rpx;
					}

					.active {
						font-weight: bold;
					}
				}

			}

			.shopping {
				padding: 0 32rpx;
				margin: 40rpx 0 0 0;
				image {
					width: 330rpx;
					height: 240rpx;
				}
			}

			.aa {
				/* #ifdef MP-TOUTIAO */
				height: 48px;
				/* #endif */
			}

			// 轮播
			.swiper {
				margin: 40rpx 30rpx;
			}
			
			.list-box {
				margin: 40rpx 30rpx;
				.each-box {
					width: 638rpx;
					// height: 220rpx;
					background: #FFFFFF;
					border-radius: 24rpx 24rpx 24rpx 24rpx;
					opacity: 1;
					margin: auto;
					padding: 24rpx;
					margin-top: 24rpx;
					display: flex;
					align-items: center;
					.img {
						width: 220rpx;
						height: 220rpx;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						opacity: 1;
						position: relative;
						// background-color: #333333;
						image {
							width: 220rpx;
							height: 220rpx;
							border-radius: 16rpx 16rpx 16rpx 16rpx;
						}
						.video_img {
							position: absolute;
							top: 5rpx;
							left: 5rpx;
						}
					}
					.text-box {
						flex: 1;
						margin-left: 32rpx;
						
						.title {
							font-size: 32rpx;
							font-weight: bold;
							color: #333333;
							.top {
								font-size: 24rpx;
								font-weight: 500;
								color: #333333;
								padding: 5rpx 8rpx;
								background: #FEBF4E;
								border-radius: 4rpx 4rpx 4rpx 4rpx;
								opacity: 1;
								display: inline-block;
								margin-right: 10rpx;
							}
						}
						.tags {
							margin-top: 21rpx;
							width: 380rpx;
							overflow: hidden;
							overflow-x: auto;
							white-space: nowrap;
							.each-tag {
								font-size: 20rpx;
								padding: 5rpx 8rpx;
								font-weight: 500;
								color: #666666;
								background-color: #F6F6F6;
								margin-right: 8rpx;
							}
						}
						.parameter {
							font-size: 22rpx;
							font-weight: 500;
							color: #333333;
							margin-top: 16rpx;
						}
						.price {
							font-size: 22rpx;
							font-weight: 800;
							color: #FA6759;
							margin-top: 18rpx;
							.text {
								font-size: 34rpx;
							}
						}
					}
					
				}
			}
		}

	}
	
	.issue {
		width: 60rpx;
		height: 60rpx;
		background: linear-gradient(180deg, #FECB6F 0%, #FFAE1C 100%);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		opacity: 1;
		border-radius: 50%;
		font-size: 24rpx;
		font-weight: bold;
		color: #333333;
		padding: 20rpx;
		text-align: center;
		position: fixed;
		right: 32rpx;
		bottom: 200rpx;
	}
	
	.serveBox {
				display: flex;
				align-items: center;
				justify-content: space-around;
				flex-direction: column;
				padding: 50rpx;
				width: 460rpx;
	
				.icon {
					width: 300rpx;
					height: 300rpx;
				}
	
				.word {
					font-size: 28rpx;
					color: #999;
					margin-top: 20rpx;
				}
			}
</style>
